package com.pt.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pt.eduservice.entity.EduTeacher;
import com.pt.eduservice.entity.TeacherQuery;
import com.pt.eduservice.mapper.EduTeacherMapper;
import com.pt.eduservice.service.TeacherService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * 条件分页查询
 *
 */

@Service
public class TeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements TeacherService {


    @Override
    public void pageQuery(Page<EduTeacher> pageParam, TeacherQuery teacherQuery) {

        QueryWrapper<EduTeacher> queryWrapper = new QueryWrapper<>();
      //  queryWrapper.orderByAsc("order");


        if (teacherQuery==null){
          baseMapper.selectPage(pageParam, null);
            return;
        }


        String name = teacherQuery.getName();

        Integer level = teacherQuery.getLevel();

        String begin = teacherQuery.getBegin();

        String end = teacherQuery.getEnd();

        if(!StringUtils.isEmpty(name)){
            //模糊查询
            queryWrapper.like("name",name);
        }

        if(!StringUtils.isEmpty(level)){
            //等值查询
            queryWrapper.eq("level",level);
        }

        if(!StringUtils.isEmpty(begin)){
            //开始时间
            queryWrapper.ge("gmt_create",begin);
        }

        if(!StringUtils.isEmpty(end)){
            //结束时间
            queryWrapper.le("gmt_create",end);
        }


        baseMapper.selectPage(pageParam,queryWrapper);


    }



}
